/*
 * ASTNode.h
 *
 *  Created on: 2010-6-1
 *      Author: Guobc
 */

#ifndef ASTNODE_H_
#define ASTNODE_H_

#include <string>
#include <map>
#include "ASTDom.h"
#include "ASTNodeList.h"
using namespace std;

namespace HA {

class ASTDom;
class ASTNodeList;
class ASTNode {
public:

	ASTNode() {

	}

	/**
	 * Sets string contents of the node
	 * @param text The new text for the node
	 */
	virtual void setText(const string& text) = 0;

	/**
	 * Returns the text of the node.
	 * @return The contents of the string or remark node, and in the case of
	 * a tag, the contents of the tag less the enclosing angle brackets.
	 */
	virtual string getText() = 0;

	/**
	 * Sets the starting position.
	 * @param start The new start position.
	 */
	virtual void setStartLine(int start) = 0;

	/**
	 * Gets the starting position.
	 * @return This is character(not byte) offset of this node in the document.
	 */
	virtual int getStartLine() const = 0;

	/**
	 * Sets the ending position.
	 * @param end The new end position.
	 */
	virtual void setEndLine(int end) = 0;

	/**
	 * Gets the ending position.
	 * @return This is character(not byte) offset of character following this node
	 * in the document.
	 */
	virtual int getEndLine() const = 0;

//	/**
//	 * Sets document this node came from.
//	 */
//	virtual void setDocument(ASTDom* document) = 0;
//
//	/**
//	 * Gets document this node came from.
//	 */
//	virtual ASTDom* getDocument() const = 0;

	/**
	 * Sets the parent of this node.
	 * @param parent The parent of this node.
	 */
	virtual void setParent(ASTNode* parent) = 0;

	/**
	 * Gets the parent of this node.
	 * @return The parent of this node, if it's been set, NULL otherwise.
	 */
	virtual ASTNode* getParent() const = 0;

	/**
	 * Append a child to this node.
	 * @param child The child node of this node.
	 */
	virtual void appendChild(ASTNode* child) = 0;

	/*/
	 * Gets the first child of this node.
	 * @return The first child in the list of children contained by this node.
	 */
	virtual ASTNode* getFirstChild() const = 0;

	/**
	 * Gets the last child of this node.
	 * @return The last child in the last of children contained by this node.
	 */
	virtual ASTNode* getLastChild() const = 0;

	/**
	 * Gets the previous sibling to this node
	 * @return The previous sibling to this node if one exists.
	 */
	virtual ASTNode* getPreviousSibling() = 0;

	/**
	 * Gets the next sibling to this node.
	 * @return The next sibling to this node if none exists.
	 */
	virtual ASTNode* getNextSibling() = 0;

	/**
	 * Gets children of this node.
	 * @return The list of children contained by this node if has one or more child.
	 */
	virtual ASTNodeList getChildren() const = 0;

	/**
	 * Test whether this node has children
	 */
	virtual bool hasChildren() const = 0;

	/**
	 * Test whether two nodes are equal.
	 * @param node The node been tested.
	 */
	virtual bool operator==(ASTNode& node) = 0;

	/**
	 * Return the HTML for this node.
	 * This should be the sequence of characters that were encountered by
	 * the parser that caused this node to be created. Where this breaks down is
	 * where broken nodes (tags and remarks) have been encountered and fixed.
	 * Applications reproducing html can use this method on nodes which are to
	 * be used or transferred as they were received or created.
	 * @return The sequence of characters that would cause this node
	 * to be returned by the parser or lexer.
	 */
	virtual string toHTML() = 0;

	/**
	 * Allow creating an instance of this node.
	 * @return A new instance of this node.
	 */
	virtual ASTNode* newInstance() const = 0;

	~ASTNode() {

	}
};
}
#endif /* ASTNODE_H_ */
